<template>
    <div class="invoice_form_container">
        <el-form ref="baseInvoiceForm" :model="formData" :rules="rules" label-width="8em">
            <el-form-item label="发票抬头" prop="entity_name">
                <el-input v-model="formData.entity_name" placeholder="请输入发票抬头" clearable />
            </el-form-item>
            <el-form-item label="纳税人识别号" prop="entity_code">
                <el-input v-model="formData.entity_code" placeholder="请输入纳税人识别号" clearable />
            </el-form-item>
            <el-form-item label="电话" prop="entity_phone">
                <el-input v-model="formData.entity_phone" placeholder="请输入电话" clearable />
            </el-form-item>
            <el-form-item label="地址" prop="entity_address">
                <el-input type="textarea" v-model="formData.entity_address"
                          placeholder="请输入地址" maxlength="200" show-word-limit clearable />
            </el-form-item>
            <el-form-item label="开户行" prop="entity_bank">
                <el-input v-model="formData.entity_bank" placeholder="请输入开户行" clearable />
            </el-form-item>
            <el-form-item label="开户账号" prop="entity_bank_account">
                <el-input v-model="formData.entity_bank_account" v-int-new
                          placeholder="请输入开户账号" clearable />
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
export default {
    name: "InvoiceInfoForm",
    props: {
        options: {
            type: Object,
            default: null,
        },
    },
    data() {
        return {
            formData: {},
            rules: {
                entity_name: [{ required: true, message: '请输入发票抬头', trigger: 'blur' }],
                entity_code: [{ required: true, message: '请输入纳税人识别号', trigger: 'blur' }],
            },
        }
    },
    watch: {
        options: {
            handler() {
                this.init();
            },
            immediate: true,
            deep: true,
        },
    },
    methods: {
        init() {
            const _this = this;
            if (_this.options) {
                _this.formData = _this.options.row;
            }
        },
        async confirm() {
            const _this = this;
            let valid = await _this.validateForm('baseInvoiceForm');
            if (!valid) {
                return false;
            }
            let subData = $.extend({}, _this.formData);
            subData.owner_sid = -1;
            return _this.fetchData(_this.$api.API_SaveBaseInvoiceInfo, subData).then(result => {
                _this.$message.success('保存成功！');
                return true;
            }).catch(() => {
                return false;
            });
        },
    },
}
</script>

<style lang="less" rel="stylesheet/less" scoped>
.invoice_form_container {

}
</style>
